package io.buffered;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

//查找某个文件夹以.java结尾的文件代码有多少行，不包含空行
public class Demo06DirectoryLines {
    public static void main(String[] args) throws Exception {
        File file = new File("F://Test");

        bianli(file);
        getLines();
    }

    private static List<String> list = new ArrayList<>();

    private static int count = 0;

    private static void bianli(File file) throws Exception {
        File[] files = file.listFiles();
        for (File f : files) {
            if (f.isDirectory()) {
                bianli(f);
            }
            if (f.getName().endsWith(".java")) {
                list.add(f.getAbsolutePath());
            }

        }
    }

    private static void getLines() throws Exception {
        BufferedReader br;
        String s;
        for (String l : list) {
            br = new BufferedReader(new FileReader(new File(l)));
            while ((s = br.readLine()) != null) {
                if (s.trim().length() != 0)
                    count++;
            }
        }
        System.out.println(count);
    }
}
